package com.subpackage

import com.google.javascript.jscomp.CheckLevel
import com.google.javascript.jscomp.CommandLineRunner
import com.google.javascript.jscomp.Compiler
import com.google.javascript.jscomp.CompilerOptions
import com.google.javascript.jscomp.JSError
import com.google.javascript.jscomp.SourceFile
import org.apache.logging.log4j.kotlin.logger
import java.io.File

/**
 * https://developers.google.com/closure/compiler?hl=zh-cn
 *
 * https://github.com/google/closure-compiler
 *
 */
class CompressJS(args: Array<String>) : CommandLineRunner(args) {


    override fun createOptions(): CompilerOptions {
        val compilerOptions = super.createOptions()
//        compilerOptions.setErrorHandler { level, error ->
//            if (level == CheckLevel.ERROR) {
//                logger.error(error.lineNumber)
//            }
//        }
        return compilerOptions
    }

    override fun doRun(): Int {
        return super.doRun()
    }

    override fun createCompiler(): Compiler? {
        return super.createCompiler()
    }


    override fun createInputs(
        files: List<FlagEntry<JsSourceType?>?>?,
        jsonFiles: List<JsonFileSpec?>?,
        allowStdIn: Boolean,
        jsChunkSpecs: List<JsChunkSpec?>?
    ): List<SourceFile?>? {
        return super.createInputs(files, jsonFiles, allowStdIn, jsChunkSpecs)
    }

    override fun createExterns(options: CompilerOptions?): List<SourceFile?>? {
        return super.createExterns(options)
    }

    override fun addAllowlistWarningsGuard(options: CompilerOptions?, allowlistFile: File?) {
        super.addAllowlistWarningsGuard(options, allowlistFile)
    }


}
